//
//  GameState.h
//  puzzle
//
//  Created by omega on 09/05/05.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "touchHell.h"

//-----------
// defines

#define PANEL_SIZE				(32.0f)
#define PANEL_FIELD_W			(8)
#define PANEL_FIELD_H			(14)

#define PANEL_NEXT_QUEUE_LEN	(4)

#define PANEL_FIELD_H_BORDER	(10)

#define PANEL_ERASE_TIME_CLEAR	(120)//(150)
#define PANEL_ERASE_TIME_AFFECT	(4)//(5)

#define PANEL_FALL_SPEED_NORMAL	(0.4f)//(0.3f)
#define PANEL_FALL_SPEED_PLAYER	(0.5f)//(0.4f)

#define PANEL_RAISE_BORDER		(8*6)
#define PANEL_RAISE_SPEED		(0.2f)

#define DONTCARE_INT			(0)

#define PANEL_FIELD_OFFSET_X	(-128.0f+16.0f)
#define PANEL_FIELD_OFFSET_Y	(-32.0f*9+8.0f)
#define PANEL_NEXT_OFFSET_X		(-128.0f+16.0f)
#define PANEL_NEXT_OFFSET_Y		(32.0f*6+16.0f)


//-----------
// struct & enum

typedef enum{
	PANEL_TYPE_NONE = 0,
	PANEL_TYPE_RED,
	PANEL_TYPE_BLUE,
	PANEL_TYPE_GREEN,
	PANEL_TYPE_MAX,
	PANEL_TYPE_RAND
} Panel_Type;

typedef enum{
	PANEL_STATE_STAYING = 0,
	PANEL_STATE_FALLING ,
//	PANEL_STATE_PRE_ERASING,
	PANEL_STATE_ERASING 
} Panel_State;


typedef struct{
	Panel_Type type;
	Panel_State state;
	int timer;
	float fall_diff;
	bool is_player_droped;
} Panel;


typedef struct{
	Panel panel[PANEL_FIELD_W][PANEL_FIELD_H];
	Panel_Type next_line[PANEL_FIELD_W][PANEL_NEXT_QUEUE_LEN];
	int player_timer;
	int erasing_timer;
	unsigned int score;
	float raised_field;
	int scrolled_dist;
	int cleared_panel_counter;
} PlayState;

//------------
// functions

void GameState_initLoad();
void GameState_update();
void GameState_draw();
bool GameState_saveState();
bool GameState_resumeState();
void GameState_callbackTouchBegan( Hell_TouchEvent* touchevents , int eventCount );
void GameState_callbackTouchMoved( Hell_TouchEvent* touchevents , int eventCount );
void GameState_callbackTouchEnded( Hell_TouchEvent* touchevents , int eventCount );

int get_gain_score_for_view( int chain_counter , int continuing_chain_counter , int continuing_counter );

void GameState_initLoad();
void GameState_update();
void GameState_draw();
bool GameState_saveState();
bool GameState_resumeState();
void GameState_callbackTouchBegan( Hell_TouchEvent* touchevents , int eventCount );
void GameState_callbackTouchMoved( Hell_TouchEvent* touchevents , int eventCount );
void GameState_callbackTouchEnded( Hell_TouchEvent* touchevents , int eventCount );

int get_gain_score_for_view( int chain_counter , int continuing_chain_counter , int continuing_counter );
